<?php
/**
* @package readerTemplate
* @author Jan Papousek
* @copyright Jan Papousek 2007
* @link http://ctenar.cz
*/
/**
* Formular pro pridani diskusniho prispevku.
* @package readerTemplate
*/
class FormCompetition extends Form {

	
	private $update = FALSE;
	
	public function __construct($id = NULL) {
		if ($id) {
			$update = TRUE;
		}
		parent::__construct("formCompetition","competition.php?action=formCompetition","post",$id);
	}
	
	public function renderForm($name,$action,$method,$enctype) {
		parent::renderForm($name,$action,$method,$enctype);
		$this->setID("formCompetition");
		if ($this->update) {
			$legend = Lng::CHANGE_COMPETITION;
		}
		else {
			$legend = Lng::ADD_COMPETITION;
		}
		$this->addFieldset($legend);
		$follow = Page::get("follow");
		$this->addTextInput(TRUE,"title",Lng::COMPETITION_NAME.":");
		$this->addSelect(TRUE,"category",Competition::getTopics(),Lng::COMPETITION_CATEGORY);
		$this->addTextarea(TRUE,"disContent",Lng::COMPETITION_INFO.":");
		$this->addSubmitButton("formCompetitionSubmitButton",$legend);
	}	
	
	protected function isSend() {
		if (Page::post("formCompetitionSubmitButton")) {
			return TRUE;
		}
		else {
			FALSE;
		}
	}
	
	protected function getDataToFill($id) {
		$comp = Discussion::getInfo($id);
		return array("title" => ($comp->title),"disContent" => $comp->content);
	}
	
	protected function execute() {
		$dis = Discussion::create(Page::post("category"),Page::post("disContent"),Page::get("follow"),Page::post("title"));
		Header("Location: competition.php?comp=".$dis->id);
	}
	
	public function getValue() {
		$owner = Page::session("login");
		if ($owner->level > User::LEVEL_BAN) {
			$string = new String(Lng::TEXT_FORMAT_TEXT,FALSE);
			$this->addValue($string);
			unset($string);
			return parent::getValue();
		}
	}	
}
?>